﻿<UserControl x:Class="NuGet.Client.VisualStudio.UI.InfiniteScrollList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:resx="clr-namespace:NuGet.Client.VisualStudio.UI.Resources"
             xmlns:self="clr-namespace:NuGet.Client.VisualStudio.UI"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:tp="clr-namespace:Microsoft.VisualStudio.ExtensionsExplorer.UI;assembly=Microsoft.VisualStudio.ExtensionsExplorer.UI"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type self:LoadingStatusIndicator}">
            <Grid Margin="0,8">                
                <TextBlock Name="_noItemsFound"
                           FontStyle="Italic"
                           HorizontalAlignment="Center"
                           Text="{x:Static resx:Resources.Text_NoItemsFound}"
                           Visibility="Collapsed" />

                <TextBlock Name="_ready"
                           HorizontalAlignment="Center"
                           Text="{x:Static resx:Resources.Text_Ready}"
                           Visibility="Collapsed" />

                <StackPanel Orientation="Vertical"
                            Name="_progressBar"
                            Visibility="Collapsed">
                    <ProgressBar
                        Margin="24,0"
                        Height="15" IsIndeterminate="True" />
                    <TextBlock Margin="0,8"
                               Text="{Binding Path=LoadingMessage}"
                               HorizontalAlignment="Center" />
                </StackPanel>
                
                
                <StackPanel Orientation="Vertical" Name="_errorOccurred"
                            Visibility="Collapsed">
                    <Button Click="RetryButtonClicked"
                            Content="{x:Static resx:Resources.Button_Retry}"
                            MinWidth="150" />
                    <Expander Margin="0,8,0,0"
                              Header="{x:Static resx:Resources.Text_ErrorDetails}"
                              >
                        <TextBox 
                             IsReadOnly="True"
                             TextWrapping="Wrap"
                             Text="{Binding ErrorMessage}" />
                    </Expander>
                </StackPanel>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=Status}" Value="Loading">
                    <Setter TargetName="_progressBar"
                            Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Status}" Value="Ready">
                    <Setter TargetName="_ready"
                            Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Status}" Value="NoItemsFound">
                    <Setter TargetName="_noItemsFound"
                            Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Status}" Value="ErrorOccured">
                    <Setter TargetName="_errorOccurred"
                            Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <Style x:Key="FocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <!--
        <SolidColorBrush x:Key="Item.MouseOver.Background" Color="#1F26A0DA" />
        <SolidColorBrush x:Key="Item.MouseOver.Border" Color="#a826A0Da" />
        <SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="#3DDADADA" />
        <SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="#FFDADADA" />
        <SolidColorBrush x:Key="Item.SelectedActive.Background" Color="#3D26A0DA" />
        <SolidColorBrush x:Key="Item.SelectedActive.Border" Color="#FF26A0DA" /> -->
    </UserControl.Resources>
    <ListBox x:Name="_list"
             Background="{DynamicResource {x:Static resx:Brushes.ListPaneBackground}}"
             Foreground="{DynamicResource {x:Static resx:Brushes.UIText}}"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             ScrollViewer.VerticalScrollBarVisibility="Visible"
             BorderThickness="0,0,0,1"
             HorizontalContentAlignment="Stretch"
             SelectionChanged="_list_SelectionChanged"
             Loaded="_list_Loaded">

        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">                
                <Setter Property="Padding" Value="0" />         
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
                <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border x:Name="Bd" BorderThickness="0" Background="{TemplateBinding Background}" Padding="0" SnapsToDevicePixels="true">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsMouseOver" Value="True" />
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Background" TargetName="Bd" 
                                            Value="{DynamicResource {x:Static tp:ColorResources.ContentMouseOverBrushKey}}" />
                                </MultiTrigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="Selector.IsSelectionActive" Value="False" />
                                        <Condition Property="IsSelected" Value="True" />
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static tp:ColorResources.ContentInactiveSelectedBrushKey}}" />
                                </MultiTrigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="Selector.IsSelectionActive" Value="True" />
                                        <Condition Property="IsSelected" Value="True" />
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static tp:ColorResources.ContentSelectedBrushKey}}" />
                                    <Setter Property="TextBlock.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static tp:ColorResources.ContentSelectedTextBrushKey}}" />
                                </MultiTrigger>                                
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
</UserControl>